//https://www.npmjs.com/package/p-map
//https://www.npmjs.com/package/delay
const pMap = require('p-map');
const delay = require('delay');

//https://www.cnblogs.com/xutongbao/p/11915700.html
function getRandomIntInclusive(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值，含最小值 
}

(async () => {
    const arr = [];
    for (let i = 1; i <= 100; i++) {
        arr.push(i);
    }
    const mapper = async v => {
        let random = getRandomIntInclusive(100, 2000);
        await delay(random);
        return Promise.resolve(v * 2);
    };

    console.time('aa');
    const result = await pMap(arr, mapper, { concurrency: 10, stopOnError: false });
    console.log(result);
    console.timeEnd('aa');

})();